import { ReqUserInfo, ReqLogout } from '@/api';
import { deleteToken } from '@/utils/auth';
const state = {
  user: {},
};
const mutations = {
  SAVE_USER_LIST(state, value) {
    state.user = value;
  },
  SAVE_LOGOUT_LIST(state) {
    state.user = {};
  },
};
const actions = {
  async asyncGetUser({ commit }) {
    try {
      let result = await ReqUserInfo();
      commit('SAVE_USER_LIST', result);
    } catch (error) {
      return Promise.reject();
    }
  },
  async asyncLogout({ commit }) {
    try {
      await ReqLogout();
      deleteToken();
      commit('SAVE_LOGOUT_LIST');
    } catch (error) {
      return Object.reject();
    }
  },
};
const getters = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
